package leetcode_day._2021._202105._2131;

import java.util.Arrays;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/5/24 21:55
 * 奇怪的打印机
 * 算法：动态规划
 */
public class _24_664 {
    public static void main(String[] args) {
        System.out.println(new _24_664().strangePrinter("aba"));
    }

    public int strangePrinter(String s) {
        int n = s.length();
        int[][] dp = new int[n][n];
        for (int i = n - 1; i >= 0; i--) {
            dp[i][i] = 1;
            for (int j = i + 1; j < n; j++) {
                if (s.charAt(i) == s.charAt(j)) dp[i][j] = dp[i][j - 1];
                else {
                    int min = Integer.MAX_VALUE;
                    for (int k = i; k < j; k++) min = Math.min(min, dp[i][k] + dp[k + 1][j]);
                    dp[i][j] = min;
                }
            }
        }
        System.out.println(Arrays.deepToString(dp));
        return dp[0][n - 1];
    }

}
